package com.green.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.green.constant.enums.GenderEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GenderConverter implements Converter<Integer> {

    private static final Logger log = LoggerFactory.getLogger(GenderConverter.class);

    /**
     * 读的时候会调用
     *
     * @param cellData
     * @param contentProperty
     * @param globalConfiguration
     * @return
     * @throws Exception
     */
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        //获取读取的字符串
        String gender = cellData.getStringValue();
        log.info("gender:{}", gender);
        //转换成对应的数据
        return GenderEnum.getCodeByLabel(gender);
    }
}
